<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/displaytag-11.tld" prefix="display"%>
<%@page import="java.util.*"%>
<link href="<%= request.getContextPath() + "/css/bloques.css" %>" rel="stylesheet" type="text/css">

<script language="javascript">
  
  var checkflag = "false";
  function check(tamano) {
    var nom = "";
    if (checkflag == "false") 
    {
      for (i = 0; i < tamano; i++) 
      {
        nom = "subprograma"+i;
        document.forms['formseleccionpermisos'].elements[nom].checked = true
      }
      checkflag = "true";
      return "Uncheck All"; 
    }
    else {
      for (i = 0; i < tamano; i++) 
      {
        nom = "subprograma"+i;
        document.forms['formseleccionpermisos'].elements[nom].checked = false
      }
      checkflag = "false";
      return "Check All"; 
    }
  }
  
  function buscarSubprogramas(){
    document.formseleccionpermisos.action = '<%=request.getContextPath()+"/User/SelectionPermissionReport.do"%>'
    document.formseleccionpermisos.submit();
  }
  
  function validarOtros(tamano)
  {
    var nom = "";
    var marcado = false;
    for (i = 0; i < tamano; i++) 
    {
      nom = "subprograma"+i;
      if (document.forms['formseleccionpermisos'].elements[nom].checked) 
      {
        marcado = true;
        break;
      }  
    } 
    if (marcado == false)
    {
      alert('Por favor seleccione una opcion.');
    }else
    {
      document.formseleccionpermisos.submit();
    }
  }
  
  function enviar(locacion1)
  {
    document.formseleccionpermisos.action=locacion1;
    document.formseleccionpermisos.submit();
  }
  
</script>
<script src="<%=request.getContextPath()%>/js/displaytag.js" type="text/javascript"></script>

  <form name="formseleccionpermisos" action="<%=request.getContextPath()+"/User/AllocationPermissionReport.do"%>" method="get">
  <table cellspacing="3" cellpadding="2" border="0" width="70%" align="center">
    <tr>
      <td class="titulosenblanco" colspan="3">
        <DIV align="center">
          <STRONG>Asignar Permisos a los Usuarios</STRONG>
        </DIV>
      </td>
    </tr>
    <tr>
      <td class="titulosenblanco" colspan="3">&nbsp;</td>
    </tr>
    <tr>
      <td align="center" class="celdatabla" colspan="3">Seleccione cada una de las siguientes opciones</td>
    </tr>
    <tr>
      <td class="titulosenblanco" colspan="3">&nbsp;</td>
    </tr>
    <tr>
      <td class="celdatabla" width="31%">Secretaria:</td>
      <td width="44%">
        <logic:notPresent scope="request" name="secretarias">
          <DIV align="center">
            <%= request.getAttribute("msg")%>
          </DIV>
        </logic:notPresent>
         <%   Object codeSecret = request.getParameter("codeArea"); 
              if(codeSecret==null) codeSecret = "nulo";
         %>
          <div align="left">
            <logic:present scope="request" name="secretarias">
              <logic:iterate id="secret" name="secretarias" length="1" type="com.cs.beneficios.business.model.ProgramaVO">
                <html:select name="secret" property="codeArea" title="Secretaria" styleClass="form" value="<%=(String)codeSecret%>" onchange="buscarSubprogramas();">
                  <option value="nulo" selected="selected">Seleccione una secretaria</option>
                  <html:options name="secret" labelName="codeSecret" labelProperty="nombreArea" property="codeArea" collection="secretarias"/>
                </html:select>
              </logic:iterate>
            </logic:present>
          </div>
      </td>
      <td class="celdatabla" width="25%">&nbsp;</td>
    </tr>
    
    
    <logic:present name="programas" scope="request">
    <tr>
      <td class="celdatabla" width="31%">Programa:</td>
      <td width="44%">
        
          <%   Object codePrograma = request.getParameter("codePrograma"); %>
          <div align="left">
            <logic:present name="programas">
              <logic:iterate id="programa" name="programas" length="1" type="com.cs.beneficios.business.model.ProgramaVO">
                <html:select name="programa" property="codePrograma" onchange="buscarSubprogramas('BuscarSubprogrmas');" title="Programa" styleClass="form" value="<%=(String)codePrograma%>">
                  <option value="nulo">Seleccione un programa</option>
                  <html:options name="programas" labelName="codigo" labelProperty="nombre" property="code" collection="programas"/>
                </html:select>
              </logic:iterate>
            </logic:present>
          </div>
        
      </td>
      <td class="celdatabla" width="25%">&nbsp;</td>
    </tr>
    </logic:present>
    <logic:notPresent scope="request" name="programas">
       <logic:present scope="request" name="msg">
        <tr>
          <td class="celdatabla" width="31%">Programa:</td>
          <td width="44%">
            <DIV align="center">
              <%= request.getAttribute("msg")%>
            </DIV>
          </td>
        </tr>
      </logic:present>
    </logic:notPresent>
  </table>
  <br/>
  <logic:present scope="request" name="subprogramas">
      <table cellspacing="3" cellpadding="2" border="0" width="60%" align="center">
          <%
            String strnombre = "";
            List lsubprog = (List)request.getAttribute("subprogramas");
            int tamano = lsubprog.size();
            int i = 0;
          %>
        <tr>
          <td align="right">
            <font class="celdatabla">Seleccionar Todos</font><input type="checkbox" name="SLT_ALL" value="Check All" onClick="this.value=check(<%=tamano%>)"/>  
          </td>
        </tr>
        <tr>
          <td>
            <display:table name="requestScope.subprogramas" id="subpro" cellpadding="3" cellspacing="1" style="width:100%" class="bordestable">
              <display:column headerClass="headerTable" title="NOMBRE DEL BENEFICIO" class="Numero" property="nombre" sortable="true"></display:column>
              <display:column headerClass="headerTable" title="Escoger" class="Numero">
                <div align="center">
                  <%
                    strnombre = "subprograma"+i;
                  %>
                  <input type="checkbox" name="<%=strnombre%>" value="<bean:write name="subpro" property="code"/>"/>
                  <%
                    i++;
                  %>
                </div>
              </display:column>
            </display:table>
          </td>
        </tr>
      </table>
    <br/>
    <div align="center">
      <input type="button" value="Continuar" onclick="validarOtros(<%=tamano%>)"/>  
    </div>
  </logic:present>
  <%String Ruta2 = "'"+request.getContextPath() + "/admin/manageUsers.do'";%>
  <br/>
  <div align="center">
    <input type="image" onclick="enviar(<%=Ruta2%>)" src="<%= request.getContextPath() + "/images/b_atras.gif"%>"/>
  </div>
</form>